
require 'RMagick'
include Magick

def drawMap(map, elements)

	img = Image.new(map.width, map.height)
	
	view = img.view(0, 0, map.width, map.height)
	
	colours = genRandomColours(elements)

	w = map.width - 1
	h = map.height - 1

	puts w, h, ""

	for x in (0..w)
	
		for y in (0..h)
		
			if map.cell(x,y)-1 < WATERBODY_START
				r = colours[map.cell(x,y)-1][0]
				g = colours[map.cell(x,y)-1][0]
				b = colours[map.cell(x,y)-1][0]
			else
				r = 0
				g = 0
				b = MaxRGB
			end
		
			view[y][x].red = r
			view[y][x].green = g
			view[y][x].blue = b
		
		end
	
	end
	
	
	view.sync
	
	img.scale!(10)

		
	return img.export_pixels_to_str

end

def genRandomColours(elements)

	colours = []

	for i in (0..elements-1)
	
		r = rand(256) * 256
		g = rand(256) * 256
		b = rand(256) * 256
	
		colours << [r, g, b]
	
	end

	return colours

end
